package Text1;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        while (m-- > 0) {
            int x = in.nextInt();
            divide(x);
        }
    }

    private static void divide(int x) {
        for (int i = 2; i <= x / i; i++) {
            if (x % i == 0) {
                int s = 0;
                while (x % i == 0) {
                    x /= i;
                    s++;
                }
                System.out.println(i + " " + s);
            }
        }
        if (x > 1) {
            System.out.println(x + " " + 1);
        }
        System.out.println();
    }
}
